﻿<?php
require_once('../../config.php');
 require_once($CFG->libdir . '/adminlib.php');
 require_once($CFG->dirroot . '/local/myplugin/lib.php');
require_once($CFG->dirroot . "/local/myplugin/forms.php");


global $DB;
$option=array();

/* Ket noi den file javascript - module.js */
$PAGE->requires->js_init_call('M.local_myplugin');	
$cssdir =  $CFG->wwwroot.'/local/myplugin/mycss.css';
echo '<link rel="stylesheet" href="'.$cssdir.'" type="text/css" media="screen" />';
//echo '<link rel="stylesheet" href="style.css" type="text/css" media="screen" />';

/* Chuan bi trang web can hien thi */	
$url = new moodle_url($CFG->wwwroot.'local/myplugin/select_block_of_knowledge.php');
$PAGE->set_url($url);
$PAGE->set_title('Choice Block of Knowledge');
$PAGE->set_heading('Choice Block of Knowledge');
$PAGE->set_pagelayout('standard');

//Them thanh menu ngang ung voi trang trong duong link
navigation_node::override_active_url(new moodle_url($CFG->wwwroot.'/local/myplugin/select_block_of_knowledge.php', array('param'=>'value')));

echo $OUTPUT->header();

/* Viet doan code cua ban o day */
//add tab vào trang
$mylib = new curriculum_management();
//set tab hien tai 
$mylib ->view_tabs('addblock');

$choose_block_knowledge_form = new form_choose_block_knowledge();
//bat su kien nhan nu cancel
if ($choose_block_knowledge_form->is_cancelled()) {

echo 'hủy thao tác';

}

//kiem tra neu dc submitted thì làm gì
if ($fromform = $choose_block_knowledge_form->get_data()) 
{
	//lay program id va major id tu combobox
	//vì 2 ku nay ghep voi nhau bang dau + nen phai cat chuoi de lay major id,  dang ghep chuoi program_id+major_id
	$pro_maj_id= $fromform->cbprogram;
	//ham cat chuoi
	$id_array= explode("+", $pro_maj_id);
	$major_id=$id_array[1];
	$program_id=$id_array[0];
	$block_id= $fromform->cbblock;
	
	$cbsubject=$_POST['cbchon'];
	
	foreach($cbsubject as $item)
	{
		$option['program_id']=$program_id;
		$option['subject_id']=$item;
		$option['major_id']=$major_id;
		$option['blockofknowledge_id']=$block_id;
		//kiem tra xem mon hoc này da thuoc ve khoi kien thuc này của chuyen nghanh nay cua chuong trinh này hay chua
		$sql="SELECT * FROM mdl_subject_major where program_id='".$program_id."' and subject_id='".$item."' and blockofknowledge_id='".$block_id."' and major_id='".$major_id."'";
		$foundid = $DB->get_records_sql($sql);
		if (!$foundid)
		{
			$mylib->add_pro_sub_maj_blo($option);
		}
	}
	
}

$choose_block_knowledge_form->display();
/*------Ket thuc doan code cua ban-------*/

echo $OUTPUT->footer();

